package com.cn.wanxi.model;

public class ResultModel {
    //    所有属性用引用类型，不要用基本类型
    private String msg;
    private Integer code;
    private Integer count;
    private Object data;
    private static ResultModel resultModel;

    //    public ResultModel(String msg, Integer code, Integer count, Object data) {
//        this.msg = msg;
//        this.code = code;
//        this.count = count;
//        this.data = data;
//    }
    public static ResultModel getResultModel(String msg, Integer code, Integer count, Object data) {
        if (resultModel == null) {
            resultModel = new ResultModel();
        }
        resultModel.setData(data);
        resultModel.setCount(count);
        resultModel.setCode(code);
        resultModel.setMsg(msg);
        return resultModel;
    }

    private ResultModel() {
    }

    /**
     * 单例模式
     *
     * @param msg
     * @return
     */
    public static ResultModel getResultModelByMsg(String msg) {
        if (resultModel == null) {
            resultModel = new ResultModel();
        }
        resultModel.setMsg(msg);
        return resultModel;
    }

    /**
     * 得到影响的条数
     *
     * @param count
     * @return
     */
    public static ResultModel getResultModelByCount(int count) {
        if (resultModel == null) {
            resultModel = new ResultModel();
        }
        resultModel.setCount(count);
        return resultModel;
    }

    public static ResultModel getResultModelByAll(Object data, int count) {
        if (resultModel == null) {
            resultModel = new ResultModel();
        }
        resultModel.setCount(count);
        resultModel.setData(data);
        return resultModel;
    }
//    public ResultModel(String msg) {
//        this.msg = msg;
//    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
